package com.bluesky.webflux.oa.controller;

import com.bluesky.webflux.oa.model.OaUser;
import com.bluesky.webflux.oa.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping
    public Mono<OaUser> addUser(@RequestBody OaUser user) {
        return userService.addUser(user);
    }

    @DeleteMapping("/{id}")
    public Mono<ResponseEntity<Void>> delUser(@PathVariable String id) {
        return userService.delUser(id);
    }

    @PutMapping
    public Mono<ResponseEntity<OaUser>> updateUser(@RequestBody OaUser user) {
        return userService.updateUser(user);
    }

    @GetMapping
    public Flux<OaUser> getAllUser() {
        return userService.getAllUser();
    }

}
